<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('荣誉专利列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>荣誉名称：</label>
                                <input type="text" name="honorName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="honorState" th:with="type=${@dict.getType('cngj_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cngj:honor:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cngj:honor:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cngj:honor:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        /*var editFlag = [[${@permission.hasPermi('cngj:honor:edit')}]];
        var removeFlag = [[${@permission.hasPermi('cngj:honor:remove')}]];*/
        var honorStateDatas = [[${@dict.getType('cngj_state')}]];
        var prefix = ctx + "cngj/honor";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                modalName: "荣誉专利",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '荣誉专利',
                    visible: false
                },
                {
                    field: 'honorName',
                    align: 'center',
                    title: '荣誉名称'
                },
                {
                    field: 'honorImg',
                    align: 'center',
                    title: '电脑端荣誉图片',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },{
                    field: 'honorImgPhone',
                    align: 'center',
                    title: '移动端荣誉图片',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                /*{
                    field: 'honorSort',
                    align: 'center',
                    title: '排序 数字自增 倒叙'
                },*/
                {
                    field: 'honorState',
                    align: 'center',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(honorStateDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.honorState == "1"){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="disable(\'' + row.id + '\')"><i class="fa fa-remove"></i>停用</a>');
                        }
                        if(row.honorState == "0"){
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="enable(\'' + row.id + '\')"><i class="fa fa-remove"></i>启用</a>');
                        }
                        if(index == 0){
                            actions.push("<a class='btn btn-primary btn-xs' href='javascript:void(0)' onclick='downMove(\"" + row.id + "\",\""+index+"\")'><i class='fa fa-level-down'></i>下移</a> ");
                        }else{
                            actions.push("<a style='background-color: #8c6ac5;border-color: #8c6ac5' class='btn btn-warning btn-xs' href='javascript:void(0)' onclick='upMove(\"" + row.id + "\",\""+index+"\")'><i class='fa fa-level-up'></i>上移</a> ");
                            actions.push("<a class='btn btn-primary btn-xs' href='javascript:void(0)' onclick='downMove(\"" + row.id + "\",\""+index+"\")'><i class='fa fa-level-down'></i>下移</a> ");
                            actions.push("<a class='btn btn-success btn-xs' href='javascript:void(0)' onclick='topMove(\"" + row.id + "\",\""+index+"\")'><i class='fa fa-star'></i>置顶</a> ");
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 荣誉专利素材管理-停用 */
        function disable(id) {
            $.modal.confirm("确认要停用该条素材吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id,"honorState": '0' });
            })
        }

        /* 荣誉专利素材管理-启用 */
        function enable(id) {
            $.modal.confirm("确认要启用该条素材吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id,"honorState": '1' });
            })
        }

        function upMove(id,index) {
            //上移
            //获取上一行的id
            var allRows = $('#bootstrap-table').bootstrapTable('getData');
            $.ajax({
                type: "post",
                url: ctx+"cngj/honor/honorMove?type=1&id="+id+"&changeId="+allRows[index-1].id,
                success: function(r) {
                    debugger;
                    location.reload();
                }
            });
        }

        function downMove(id,index) {
            //下移
            //获取下一行
            debugger;
            var allRows = $('#bootstrap-table').bootstrapTable('getData');
            if(index <allRows.length-1){
                $.ajax({
                    type: "post",
                    url: ctx+"cngj/honor/honorMove?type=2&id="+id+"&changeId="+allRows[Number(index)+1].id,
                    success: function(r) {
                        debugger;
                        location.reload();
                    }
                });

            }else{
                $.modal.alertWarning("已经是最后了，不能下移！");
            }
        }

        function topMove(id,index) {
            //置顶
            var allRows = $('#bootstrap-table').bootstrapTable('getData');
            $.ajax({
                type: "post",
                url: ctx+"cngj/honor/honorMove?type=3&id="+id+"&changeId="+allRows[0].honorSort,
                success: function(r) {
                    debugger;
                    location.reload();
                }
            });
        }

    </script>
</body>
</html>